package com.yunzhong.appointment.illnesstpye.service.impl;

import com.yunzhong.appointment.entity.Illness;
import com.yunzhong.appointment.entity.Illnessposition;
import com.yunzhong.appointment.illnesstpye.service.IllnessService;
import com.yunzhong.appointment.illnesstpye.service.IllnessTypeService;
import com.yunzhong.appointment.mapper.IllnessMapper;
import com.yunzhong.appointment.mapper.IllnesspositionMapper;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IllnessServiceImpl implements IllnessService {
    @Autowired
    private IllnessMapper illnessMapper;

    @Override
    public List<Illness> query(PageData pd) {
        pd.setPageData(pd);
        return illnessMapper.query(pd);
    }

    @Override
    public Illness queryById(String id) {
        return illnessMapper.selectByPrimaryKey(id);
    }

    @Override
    public int save(Illness illnessposition) {
        return illnessMapper.insertSelective(illnessposition);
    }

    @Override
    public int edit(Illness illnessposition) {
        return illnessMapper.updateByPrimaryKeySelective(illnessposition);
    }

    @Override
    public int delete(String[] ids) {
//        StringBuilder sb = new StringBuilder();
//        for (int i=0;i<ids.length;i++){
//            //验证是否能删除，不能删除的需要把名称显示到页面上
//            String str = illnessMapper.validateDel(ids[i]);
//            if (str != null && str.length() > 0) {
//                String firstValue = str.substring(0, str.indexOf("@"));
//                String zero = "0";
//                if (zero.equals(firstValue)) {
//                    illnessMapper.deleteByPrimaryKey(ids[i]);
//
//                } else {
//                    String name = str.substring(str.indexOf("@") + 1);
//                    sb.append(name).append(",");
//                }
//            } else {
//                illnessMapper.deleteByPrimaryKey(ids[i]);
//            }
//        }
//        if (sb.length() > 0) {
//            return sb.substring(0, sb.length() - 1);
//        }
//        return "";
//    }
        int num = 0;
        for (int i = 0; i < ids.length; i++) {
            num = illnessMapper.deleteByPrimaryKey(ids[i]);

        }
        return num;
    }
}
